# -*- coding: utf-8 -*-
# @Time    : 2018/3/7 11:32
# @Author  : Deyu.Tian
# @Site    :
# @File    : config.py
# @Software: PyCharm Community Edition
import geotiff_tools as imt

def correctSoilType(soil, glacial, out):
    """
    correcrt soil type feature
    :param soil:
    :param glacial:
    :return:
    """
    imggt, soil = imt.read_tif_and_metadata(soil)
    glac = imt.read_tiff(glacial)
    print(soil.shape[0], soil.shape[1])
    for i in range(soil.shape[0]):
        for j in range(soil.shape[1]):
            if glac[i, j] == 1:
                soil[i, j] = 11930
            if glac[i, j] != 1 and soil[i, j] == 1:
                soil[i, j] = 11765
    imt.array2rasterUTM("{}/soiltype_corrected.tif".format(out), imggt, soil)
    pass


def unionSoilType(soil, out):
    """
    correcrt soil type feature
    :param soil:
    :param glacial:
    :return:
    """
    imggt, soil = imt.read_tif_and_metadata(soil)
    #glac = imt.read_tiff(glacial)
    print(soil.shape[0], soil.shape[1])
    for i in range(soil.shape[0]):
        for j in range(soil.shape[1]):
            if soil[i, j] == 11705 or soil[i, j] ==11387 or soil[i, j] == 11748 or soil[i, j] == 11747:
                soil[i, j] = 11765
            if soil[i, j] == 11303:
                soil[i, j] = 11307
            if soil[i, j] == 11230:
                soil[i, j] = 11238
    imt.array2rasterUTM("{}/soiltype_corrected_uniond.tif".format(out), imggt, soil)
    pass


if __name__ == '__main__':
    soil = "/home/deyu1/share/data-mining/lithology&soil/soiltype_corrected.tif"
    #glacial = "/home/deyu1/share/gazreasarch/optical_related_experiments/LandsatData/snowcover/FLAASH_summer_NDSI_Binary_30m_resize.tif"
    out = "/home/deyu1/share/data-mining/lithology&soil"
    #correctSoilType(soil, glacial, out)
    unionSoilType(soil, out)